package com.tang.algorithm.array;

/**
 * @author tlm
 * @version 1.0
 * @date 2020/5/16 10:32
 * 搜索二维矩阵 II
 *
 * https://leetcode-cn.com/problems/search-a-2d-matrix-ii/
 */
public class LeetCode240 {
    public boolean searchMatrix(int[][] matrix, int target) {
        int row = matrix.length-1;
        int col = 0;

        while(row>=0 && col<matrix[0].length){
            //如果大于目标值，行--
            if(matrix[row][col]>target){
                row--;
            }else if(matrix[row][col]<target){
                //如果小于目标值，列++
                col++;
            }else {
                return true;
            }
        }
        return false;
    }
}
